<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>webSocket</title>
		<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
		<script type="text/javascript" src="js/mqttws31.min.js"></script>
		<script type="text/javascript" src="js/webSocket.Paho.js"></script>
	</head>

	<body id="body">
		<div rtdata="level1/aa/tag1_num">webSocket测试1</div>
		<div rtdata="level1/aa/tag2_num">webSocket测试2</div>
		<script>
			var sun = 0;
			var host = "sealush.tpddns.cn";
			var port = 8083;
			var clientId = "example2";
			var user = "";
			var password = "";
			var destination = "level1/+/+";
			var webSock = new WebSock(host, port, clientId, user, password, destination);
			webSock.auto(true);
			console.log(webSock.getAllTag());
			$("#body").append("<div rtdata = 'level1/aa/tag3_num'> webSocket测试3 </div>");
			webSock.upDataDoms();
			console.log(webSock.getAllTag());

			function doSomeThingTag0(rtdata) {
				webSock.register(doSomeThingTag0, "level1/aa/tag0_num");
				var tag2_v = webSock.getValue(rtdata);
				if(tag2_v) {
					sun += tag2_v
					console.log(sun);
				}
			}

			function doSomeThingTag1(rtdata) {
				webSock.register(doSomeThingTag1, "level1/aa/tag0_num");
				var tag2_v = webSock.getValue(rtdata);
				if(tag2_v) {
					sun += tag2_v
					console.log(sun);
				}
			}

			function doSomeThingTag2(rtdata) {
				webSock.register(doSomeThingTag2, "level1/aa/tag0_num");
				var tag2_v = webSock.getValue(rtdata);
				if(tag2_v) {
					sun += tag2_v
					console.log(sun);
				}
			}

			doSomeThingTag0();
			doSomeThingTag1();
			doSomeThingTag2();
		</script>
	</body>

</html>